<?php


class CartController extends CommonController
{
    public function indexAction()
    {
        json(['code' => 1, 'msg' => '我的购物车', 'data' => cartModel::info()]);
    }

    public function addAction()
    {
        $params = $this->getPost();

        try {
            Validate::check($params, ['goods_list' => ['func'=>'isNotEmpty', 'msg'=>'商品']]);
        } catch (Exception $e) {
            throw new Exception($e->getMessage());
        }

        $goodsList = $params['goods_list'];
        json(['code' => 1, 'msg' => '添加成功', 'data' => cartModel::add($goodsList)]);
    }

    public function editAction()
    {
        $params = $this->getPost();
        try {
            Validate::check($params, [
                'cart_list' => ['func'=>'isNotEmpty', 'msg'=>'购物车商品'],
                'act' => ['role'=>'required', 'msg'=>'操作类型'],
            ]);
        } catch (Exception $e) {
            throw new Exception($e->getMessage());
        }
        json(['code' => 1, 'msg' => '', 'data' => cartModel::edit($params)]);
    }
}
